import { ipcRenderer, contextBridge } from 'electron';
// import sqlite3 from 'sqlite3';
// import fs from 'fs';
declare global {
  interface Window {
    Main: typeof api;
    ipcRenderer: typeof ipcRenderer;
  }
}

// 暴露 dialog 属性
// window.shell = require('electron').shell;
// window.ipcRenderer = require('electron').ipcRenderer;
// window.os = require('os');
// import * as path from 'path';
// import * as url from 'url';
// import * as fs from 'fs';
// import { open } from 'sqlite3';
// shell.openExternal(path.join(__dirname, ')
// 数据库


const api = {

  echo: (message:string)=> {
    ipcRenderer.send('echo', message);
  },
  /**
   * Here you can expose functions to the renderer process
   * so they can interact with the main (electron) side
   * without security problems.
   *
   * The function below can accessed using `window.Main.sayHello`
   */
  sendMessage: (message: string) => {
    ipcRenderer.send('message', message);
  },
  /**
    Here function for AppBar
   */
  Minimize: () => {
    ipcRenderer.send('minimize');
  },
  Maximize: () => {
    ipcRenderer.send('maximize');
  },
  Close: () => {
    ipcRenderer.send('close');
  },

  SaveUser: (user: any) => {
    ipcRenderer.send('saveUser', user);
  },
  CreateUserTable: () => {
    ipcRenderer.send('createUserTable');
  },
  /**
   * Provide an easier way to listen to events
   */
  on: (channel: string, callback: (data: any) => void) => {
    ipcRenderer.on(channel, (_, data) => callback(data));
  }
};
contextBridge.exposeInMainWorld('Main', api);
/**
 * Using the ipcRenderer directly in the browser through the contextBridge ist not really secure.
 * I advise using the Main/api way !!
 */
contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer);
